package com.sm.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRoleDao {

    /**
     * 新增员工权限 多参数 一定要用@Param("uid")指定参数名
     * @param uid 员工id
     * @param rid 要添加的权限id
     */
    @Insert("insert into user_role(rid,uid) values(#{rid},#{uid}) ")
    public void addUserRole(@Param("uid")Integer uid,@Param("rid")Integer rid)throws Exception;

    //删除该员工的所有权限
    /**
     * @param uid 要删除权限的员工ID
     * @throws Exception 所有异常
     */
    @Delete("delete from user_role where uid = #{uid}")
    public void deletRoleByUid(Integer uid)throws Exception;

    /**
     * 删除员工权限  不存在的数据 不会报错 暂时没用 使用的直接删除所有权限再添加
     * @param uid 员工id
     * @param rid 要删除的权限id
     */
    @Delete("delete from user_role where uid = #{uid} and rid = #{rid} ")
    public void delUserRole(@Param("uid")Integer uid,@Param("rid")Integer rid)throws Exception;

//    /**
//     * 更新员工权限  不存在的数据 不会报错
//     * @param uid 员工id
//     * @param rid 修改员工id
//     */
//    @Update("update user_role set rid = #{rid} where uid = #{uid}")
//    public void updateUserRole(@Param("uid") Integer uid, @Param("rid") Integer rid);
}
